//
//  XHRLoginRegisterViewController.m
//  BuDeJie
//
//  Created by haoran on 16/4/5.
//  Copyright © 2016年 xuhaoran. All rights reserved.
//

#import "XHRLoginRegisterViewController.h"
#import "XHRLoginRegisterView.h"
#import "XHRFastLoginView.h"

@interface XHRLoginRegisterViewController ()
@property (weak, nonatomic) IBOutlet UIButton *closeBtn;
@property (weak, nonatomic) IBOutlet UIButton *loginRegisterBtn;

@property (weak, nonatomic) IBOutlet UIView *middleView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadingConstrain;


@property (weak, nonatomic) IBOutlet UIView *bottomView;

@end

@implementation XHRLoginRegisterViewController

/*
 1.如果一个控件从xib加载,必须固定尺寸
 
 2.在viewDidLoad设置子控件位置,在viewDidLayoutSubviews布局子控件
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    // 默认一个view从xib加载,尺寸跟xib一样
    //添加登录view
    XHRLoginRegisterView * view1 = [XHRLoginRegisterView loginView];
    [self.middleView addSubview:view1];
    
    //添加注册View
    XHRLoginRegisterView * view2 = [XHRLoginRegisterView registerView];
    view2.xhr_x = self.middleView.xhr_width * 0.5;
    [self.middleView addSubview:view2];
    
    //添加款速登录View
    XHRFastLoginView * fastView = [XHRFastLoginView fastloginView];
    [self.bottomView addSubview:fastView];
    
    
}



- (IBAction)closeBtnClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)loginRegisterBtnClick:(UIButton *)btn {
    
    btn.selected = !btn.selected;
    
    //移动中间的view
    self.leadingConstrain.constant = self.leadingConstrain.constant==0? -self.middleView.xhr_width * 0.5:0;
    //动画执行
    [UIView animateWithDuration:0.25 animations:^{
        //重新布局子控件
        [self.view layoutIfNeeded];
    }];
}

// 执行约束,里面尺寸才是最准确.
-(void)viewDidLayoutSubviews{
    [super viewDidLayoutSubviews];
    
    //设置登录
    XHRLoginRegisterView *loginView = self.middleView.subviews[0];
    loginView.frame = CGRectMake(0, 0, self.middleView.xhr_width * 0.5, self.middleView.xhr_height);
    //设置注册
    XHRLoginRegisterView *registerView = self.middleView.subviews[1];
    registerView.frame = CGRectMake(self.middleView.xhr_width * 0.5, 0, self.middleView.xhr_width * 0.5, self.middleView.xhr_height);
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
